package com.sjh;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author jack
 * @data 2020/8/21 3:30 下午
 */
public class LockTest {
    public static void main(String[] args) {
        OutPut outPut = new OutPut();
        while (true) {
            new Thread(new Runnable(){

                @Override
                public void run() {
                    outPut.outPut("jackLove");
                }
            }).start();

            new Thread(new Runnable(){

                @Override
                public void run() {
                    outPut.outPut("TraditionalSynchronizeThread");
                }
            }).start();
        }
        }

    static class OutPut{
        Lock lock = new ReentrantLock();
        public void outPut(String name) {
            lock.lock();
            try {
                for (int i = 0; i < name.length(); i++) {
                    System.out.print(name.charAt(i));
                }
                System.out.println();
            } finally {
                lock.unlock();
            }
        }

    }
}

